import Vue from 'vue'
import App from './App.vue'
import VueRouter from 'vue-router'
//import {routes} from './routes'

import Home from './components/Home'
import Menu from './components/Menu'
import About from './components/about/About'
import Admin from './components/Admin'
import Login from './components/Login'
import Register from './components/Register'

//二级路由
import History from './components/about/History'
import Contact from './components/about/Contact'
import OrderingGulde from './components/about/OrderingGulde'
import Delivery from './components/about/Delivery'

//三级路由
import PersonName from './components/about/contact/PersonName'
import Phone from './components/about/contact/Phone'


Vue.use(VueRouter)

 const routes = [
	  {path:'/',name:'homeLink',components:{
	  	default:Home,
	  	'orderingGulde':OrderingGulde,
	  	'delivery':Delivery,
	  	'history':History
	  }},
	  {path:'/menu',name:'menuLink',component:Menu},
	  {path:'/about',name:'aboutLink',redirect:'/about/contact',component:About,children:[
	  	{path:'/about/history',name:'historyLink',component:History},
	  	{path:'/about/contact',name:'contactLink',redirect:'/personname',component:Contact,children:[
	  		{path:'/personname',name:'personName',component:PersonName},
	  		{path:'/phone',name:'phone',component:Phone}
	  	]},
	  	{path:'/about/orderingGulde',name:'orderingGuldeLink',component:OrderingGulde},
	  	{path:'/about/delivery',name:'deliveryLink',component:Delivery}
	  ]},
	  {path:'/admin',name:'adminLink',component:Admin},
	  {path:'/login',name:'loginLink',component:Login},
	  {path:'/register',name:'registerLink',component:Register},
	  {path:'*',redirect:'/'}//找不到路径，跳转到指定路径
	]

const router = new VueRouter({
	routes,
	mode:"history",//必须双引号
	scrollBehavior(to,from,savePosition){
		//return{x:0, y:200}//显示滚动的位置
		//return{selector:'.btn'}//显示第一个btn
		if(savePostion){
			return savePostion
		}else{
			return{ x:0, y:0}
		}
	}
})

//全局守卫
//router.beforeEach((to,from,next)=>{
////	console.log(to)
//	//判断store.getter.isLogin === false
//	if(to.path == '/login' || to.path == '/register'){
//		next();
//	}else{
//		alert("还没有登录，请先登陆")
//		next('/login')
//	}
//})

//后置钩子（函数）
//router.afterEach((to,from)=>{
//	alert('after each')
//})


new Vue({
  el: '#app',
  router:router,//必须有
  render: h => h(App)
})
